let wwwurl = "http://localhost:9004";




/**
 * 全屏弹框方法
 * 在内嵌页面中使用
 * @param url 要打开的页面
 * @param closeFun 弹框关闭事件
 * @param buttons 右下角按钮
 * @param formData 要传给打开页面的数据
 */
function layer_max_window(url, closeFun, buttons, formData) {
	var layer_id = "" + new Date().getTime();
	var config = {
		id: layer_id,
		type: 2,
		offset: 'auto',
		anim:5,
		title: false,
		area: ["100%", "100%"],
		fixed: false, //不固定
		maxmin: false,
		closeBtn:0,
		content: url,
		success: function (layero, index) {
			// $(top.window).resize(function (){
			// 	setLayer(config,index);
			// });
			// top.window.addEventListener('resize', setLayer(index));

			if (formData) {
				try {
					var body = layer.getChildFrame('body', index);
					var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
					iframeWin.setData(formData);
				}catch (e){}
			}
		},
		end: function () {
			if (closeFun) {
				closeFun();
			}
		}, cancel: function () {
			var index = layer.getFrameIndex(layer_id); //先得到当前iframe层的索引
			layer.close(index);
			return true;
		}
	};
	if (buttons) {
		copy(buttons, config);
	}

	//iframe层-父子操作
	layer.open(config);
}



function f_layer_open(url, width, height, closeFun, buttons, title, formData) {
	if (width == "") {
		width = "60%";
	}
	if (height == "") {
		height = "90%";
	}
	var layer_id = "" + new Date().getTime();
	var config = {
		id: layer_id,
		type: 2,
		offset: '25px',
		title: title,
		area: [width, height],
		fixed: false, //不固定
		maxmin: true,
		content: url,
		success: function(layero, index) {
			if (formData) {
				try {
					var body = layer.getChildFrame('body', index);
					var iframeWin = window[layero.find('iframe')[0][
						'name'
						]]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
					iframeWin.setData(formData);
				} catch (e) {}

			}
		},
		end: function() {
			if (closeFun) {
				closeFun();
			}
		},
		cancel: function() {
			var index = layer.getFrameIndex(layer_id); //先得到当前iframe层的索引
			layer.close(index);
			return true;
		}
	};
	if (buttons) {
		copy(buttons, config);
	}

	//iframe层-父子操作
	layer.open(config);

}





function rowClick(rowid){
	var row = document.getElementById(rowid);
	if(row.checked == true){
		row.checked = false;
		$("#rel_tr_"+rowid).attr("bgcolor","");
	}else{
		row.checked = true;
		//将选中的行置为绿色
		$("#rel_tr_"+rowid).attr("bgcolor","silver");
	}
}

function checkClick(rowid){
	var row = document.getElementById(rowid);
	if(row.checked == true){
		$("#rel_tr_"+rowid).attr("bgcolor","silver");
	}else{
		//将选中的行置为绿色
		$("#rel_tr_"+rowid).attr("bgcolor","");
	}
}

function groupClick(obj){
	var ids = document.getElementsByName("ids");
	for(var a=0;a<ids.length;a++){
  		if(obj.checked == true){
  			$("#rel_tr_chk_"+a).attr("bgcolor","silver");
  		}else{
  			$("#rel_tr_chk_"+a).attr("bgcolor","");
  		}
  	}
}


/**
 * 对象属性拷贝
 * @param {} o1 要拷贝的对象
 * @param {} o2 拷贝到该对象中
 * @return {}
 */
var copy = function(o1,o2){
	for(var o in o1){
		o2[o] = o1[o];
		//eval("o2['"+o+"']=o1['"+o+"']");
	}
	return o2;
};

/**
 * 在对象属性前面添加字符串
 * @param {} obj
 * @param {} u_name 要添加的字符串
 */
var convertBean = function(config, beanName) {
		beanName = beanName || 'bean';
		beanName = beanName + '.';
		var r = '{';
		for (p in config) {
			var v = config[p];
			if(!v)v='';
			if (typeof(v) == 'string') {
				if (r != '{')
					r += ',';
				r += '"' + beanName + p + '":"'
						+ v.replace(/\"/g, '\\"') + '"';
			} else if (typeof(v) == 'number') {
				if (r != '{')
					r += ',';
				r += '"' + beanName + p + '":' + v;
			} else if (typeof(v) == 'boolean') {
				if (r != '{')
					r += ',';
				r += '"' + beanName + p + '":' + v;
			}
		}
		r += '}';
		var op = eval("("+r+")");
		return op;
	};

/**
 * 在对象属性前面添加字符串
 * @param {} obj
 * @param {} u_name 要添加的字符串
 */
var convertBean1 = function(config, beanName) {
		var map = {};
		for(var p in config){
			map[beanName+"."+p] = config[p];
		}
		return map;
};



/**
 * 修改表单数据 给表单赋值
 * @param {} obj 数据对象
 * @param {} tagName 要修改的输入项名称 说明：标签名称
 */
var setForm = function(obj,tagName,parentObj){
	var a = $(tagName);
	if(parentObj){
		a = $(parentObj).find(tagName);
	}
	var sqls = {};
    for(var i  in obj){
    	//数据库数据
    	var name = i;
    	var value = obj[i];
    	if("null" == value || null==value){
    		value = "";
    	}
    	//开始循环表单每个标签
    	for(var c=0;c<a.length;c++){
    		if($(a[c]).attr("name") == name){
    			if($(a[c]).attr("type") == "radio"){
        			$("input[name='"+$(a[c]).attr("name")+"'][value="+value+"]").attr("checked",true);
        		}else if($(a[c])[0].tagName == "select" || $(a[c])[0].tagName == "SELECT"){
        			$(a[c]).attr("default_value",value);
        			$(a[c]).val(value);
        		}else{
        			$(a[c]).val(value);
        			if($(a[c]).attr("sql") != undefined){
            			sqls[name+"!_!"+$(a[c]).attr("text")+"!_!"+$(a[c]).attr("v")] = $(a[c]).attr("sql")+" and "+$(a[c]).attr("v")+"='"+value+"' ";
        			}

        		}
    		}
    	}
    }

};

/**
 * 修改表单数据 给表单赋值
 * @param {} obj 数据对象
 * @param {} tagName 要修改的输入项名称 说明：标签名称
 */
var setFormHtml = function(obj,tagName){
	var a = $(tagName);

    for(var i  in obj){
    	//数据库数据
    	var name = i;
    	var value = obj[i];
    	if("null" == value || null==value){
    		value = "";
    	}
    	//开始循环表单每个标签
    	for(var c=0;c<a.length;c++){
    		if($(a[c]).attr("name") == name){
    			if($(a[c]).attr("type") == "radio"){
        			$("input[name='"+$(a[c]).attr("name")+"'][value="+value+"]").attr("checked",true);
        		}else{
        			$(a[c]).html(value);
        		}
    		}
    	}
    }
};






/**
 * 列表选择记录方法
 * @param {} grid
 */
var chk = function(){
	var id = [];
  	var ids = document.getElementsByName("ids");
  	for(var a=0;a<ids.length;a++){
  		if(ids[a].checked == true){
  			id.push(ids[a].value);
  		}
  	}
  	if(id.length == 0){
  		alertMsg.warn('请选择记录！');
  		return false;
  	}
  	return id;
};





/**
 * 把字符串转换为对象
 * @param {} text
 * @return {}
 */
var decode = function(text){
	//var obj = eval("("+text+")");
	return text;
};


/**
 * 得到已选择列表数据
 */
var getRowData = function(){
	var objs = [];
	var chkIds = chk();
	for(var a=0;a<chkIds.length;a++){
		var id = chkIds[a];
		var rowData = $("#rowData_"+id).text();
		objs.push(decode(rowData));
	}
	return objs;
};

/**
 * 根据标签属性得到所有对象的值
 * @param attrName 标签名称
 * @param attrValue 标签值
 * @returns 返回map对象
 */
function getValuesForm(attrName,attrValue,parentObject){
	var objs = $("["+attrName+"="+attrValue+"]");
	if(parentObject){
		objs = $(parentObject).find("["+attrName+"="+attrValue+"]");
	}
	var map = {};
	for(var a=0;a<objs.length;a++){
		if($(objs[a]).attr("type")!="radio"){
			if($(objs[a]).val() == null){
				map[$(objs[a]).attr("name")] = "";
			}else{
				if($(objs[a]).attr("sql")!=undefined){
					var vb1 = $(objs[a]).val();
					map[$(objs[a]).attr("name")] = ""+vb1.split(":")[0];
				}else{
					map[$(objs[a]).attr("name")] = ""+$(objs[a]).val();
				}
			}
		}else{
			var v = $('input[name="'+$(objs[a]).attr("name")+'"]:checked').val();
			map[$(objs[a]).attr("name")] = ""+v;
		}

	}
	return map;
}


/**
 * 根据标签属性得到所有对象的值
 * @param attrName 标签名称
 * @param attrValue 标签值
 * @returns 返回map对象
 */
function getValuesFormXml(attrName,attrValue,parentObject){
	var map = getValuesForm(attrName,attrValue,parentObject);
	var xml = "<row>";
	for(var k in map){
		xml = xml+"<"+k+"><![CDATA["+map[k]+"]]></"+k+">";
	}
	xml = xml+"</row>";
	return xml;
}

/**
 * 把map对象转换为xml数据
 * @param map
 * @returns
 */
function getValuesMap2Xml(map){
	var xml = "<row>";
	for(var k in map){
		if(k!=null && k!="" && k!=undefined && k!="undefined"){
			xml = xml+"<"+k+"><![CDATA["+map[k]+"]]></"+k+">";
		}
	}
	xml = xml+"</row>";
	return xml;
}

/**
 * 根据标签属性得到所有的对象
 * @param attrName 标签名称
 * @param attrValue 标签值
 * @parsm parentObject 上级标签的对象
 * @returns 返回map对象
 */
function getObjectForm(attrName,attrValue,parentObject){
	var objs = $("["+attrName+"="+attrValue+"]");
	if(parentObject){
		objs = $(parentObject).find("["+attrName+"="+attrValue+"]");
	}
	var map = {};
	for(var a=0;a<objs.length;a++){
		map[$(objs[a]).attr("name")] = objs[a];
	}
	return map;
}



/**
 * 把提交的数据表单进行重置
 */
function reset(attrName,attrValue){
	var objs = $("["+attrName+"="+attrValue+"]");
	for(var a=0;a<objs.length;a++){
		$(objs[a]).val("");
		var tagname = objs[a].tagName;
		if(tagname != "SELECT"){
			$(objs[a]).html("");
			$(objs[a]).text("");
		}
	}
}



/**
 * 对页面加载下拉框
 */
function loadSelectCombox(id){

	if(null!=id && ""!=id){
		var o = $("#"+id);
		loadSelectComboxForObj(o);
	}else{
		var selects = $("select");
		for(var a=0;a<selects.length;a++){
			loadSelectComboxForObj($(selects[a]));
		}
	}

}



/**
 * 对页面加载下拉框
 */
function loadSelectComboxForObj(o,funObj){
	var url = o.attr("url");
	var parms = o.attr("parms");
	var vca = o.attr("v");
	var text = o.attr("text");
	//获取默认值
	var default_value = o.attr("default_value");

	if(url!=null && url!=""){
		o.html("<OPTION value='' >加载中...</OPTION>");
		$.ajax({
			url : url,
			data : parms,
			type : "POST",
			success : function(msg){
				o.html("<OPTION value='' ></OPTION>");
				var j = msg;
				for(var c=0;c<j.length;c++){
					var v = j[c][vca];
					var name = j[c][text];

					if(default_value){
						if(v == default_value){
							o.append("<OPTION value='"+v+"' selected='selected' >"+name+"</OPTION>");
						}else{
							o.append("<OPTION value='"+v+"' >"+name+"</OPTION>");
						}
					}else{
						o.append("<OPTION value='"+v+"' >"+name+"</OPTION>");
					}
				}
				if(funObj){
					funObj.fun();
				}
			}
		});
	}

}


/**
 * 对页面加载下拉框
 */
function loadSelectCombox_fun(funObj,select_attr,parent_attr){

	var selects = $("select");
	if(select_attr!=null){
		selects = $(select_attr);
	}
	if(parent_attr!=null){
		selects = $(parent_attr).find("select");
	}

	var sqls = {};
	for(var a=0;a<selects.length;a++){
		loadSelectComboxForObj($(selects[a]),funObj);
	}

}






function getTabUrl(url){
	var tab_url = '<iframe src="'+url+'"  id="rightMain'+new Date()+'" name="rightMain'+new Date()+'"    frameborder=0 framespacing=0 scrolling=no marginheight=0 allowTransparency="true"  marginwidth=0 width="100%" height="100%" ></iframe>';
	return tab_url;
}




//获取当前列表的页码
function getPageNumber(){
	var grid = $('#grid');
	var options = grid.datagrid('getPager').data("pagination").options;
	var curr = options.pageNumber;
	return curr;
}

//获取当前列表的每页数量
function getPageSize(){
	var grid = $('#grid');
	var options = grid.datagrid('getPager').data("pagination").options;
	var curr = options.pageSize;
	return curr;
}

/**
 * 把当前页面的路径和参数添加到最顶层页面中，可以在返回的时候调用所保存的参数
 */
function setTopParams(u,params){
	var pageNumber = getPageNumber();
	params['pageNumber'] = pageNumber;
	params['pageSize'] = getPageSize();
	var obj = {url:u,parms:params};
	top.paramsData.push(obj);
}

getTopPager = function(){
	var p = {
		pageNo : 1,
		pageSize : 50
	};
	var objs = top.paramsData;
	if(objs.length == 0){
		return p;
	}else{
		var obj = objs[objs.length-1];
		try{
			var pm = obj.parms;
			var pageNumber = pm.pageNumber;
			p.pageNo = pageNumber;
			p.pageSize = pm.pageSize;
		}catch (e) {
		}
	}
	return p;
};

/**
 * 返回
 */
goBack = function(){
	var objs = top.paramsData;
	var obj = objs[objs.length-1];
	var url = obj.url;
	var pm = obj.parms;
	try{
		var p = getTopPager();
		//alert("",p.pageSize);
		top.pageNo = p.pageNo;
		top.pageSize = p.pageSize;
	}catch(e){}
	objs.pop();
	f_main_flush1(url,pm.title);
};


function f_int(v){
	var vs = v.split("");
	for(var a=0;a<vs.length;a++){
		if(!Number(vs[a])){
			return false;
		}
	}
	return true;
}

//输入框验证
function f_validInput(){
	var obj = $("[valid=true],[requir=true]");
	for(var a=0;a<obj.length;a++){
		$(obj[a]).blur(function(){
			var bl = false;
			var t = $(this).val();
			var leng = $(this).attr("maxlength");
			try{
				if(t.length>leng && Number(leng)>0){
					$(this).css("border","1px solid #F11C1C");
					return;
				}
				//是否要判断数字
				var s = $(this).attr("dataValue");
				if(s == "int"){
					if(!f_int(t)){
						$(this).css("border","1px solid #F11C1C");
						return;
					}
				}else if(s == "tel"){//手机号或电话验证
					if(!f_checkTel(t)){
						$(this).css("border","1px solid #F11C1C");
						return;
					}
				}
			}catch(e){}
			if($(this).attr("requir") == "true"){
				 var cli = this.getAttribute("onclick");
				 var text = $(this).val();
				 if(text == "" && !cli)
				 {
					 //$(this).css("border","1px solid #F11C1C");
					 //alert($(this).attr("lable")+"不能为空!");
				 }else{
					 bl = true;
					// $(this).css("border","1px solid #ccc");
				 }
			}
			if($(this).attr("valid") == "true"){
				 var text = $(this).val();
				 var str = "[@/'\"#$%&^* .,]+";
				 var strForText = text;
				 var reg = new RegExp(str);
				 if(reg.test(strForText))
				 {
					$(this).css("border","1px solid #F11C1C");
					//alert($(this).attr("lable")=="undefined"?"":$(this).attr("lable")+"有非法字符!");
				 }else if(bl){
					 $(this).css("border","1px solid #ccc");
				 }
			}
		});
	}
}
/**
 * 验证输入框
 */
function f_valid(){
	var datetime = $("[class=textbox-value]");

	var obj = $("[valid=true],[requir=true]");
	var cl = $("[cl=tx]");
	for(var c=0;c<cl.length;c++){
		$(cl[c]).remove();
	}
	for(var a=0;a<obj.length;a++){
		if($(obj[a]).attr("requir") == "true"){
			for(var r=0;r<datetime.length;r++){
				if($(datetime[r]).attr("name") == $(obj[a]).attr("textboxname")){
					$(obj[a]).attr("name",$(datetime[r]).attr("name"));
					$(obj[a]).val($(datetime[r]).val());
				}
			}
			 //$(obj[a]).parent().append('<span class="red tx" cl="tx">*</span>');
			 var text = $(obj[a]).val();
			/* if(text == "")
			 {
				 $(obj[a]).css("border","1px solid #F11C1C");
			 }else{
				 $(obj[a]).css("border","1px solid #ccc");
			 }*/
			 //$(obj[a]).css("border","1px solid #ccc");
		}
		if($(obj[a]).attr("valid") == "true"){
			 var text = $(obj[a]).val();
			 var str = "[@/'\"#$%&^* .,]+";
			 var strForText = text;
			 var reg = new RegExp(str);
			 /*if(reg.test(strForText))
			 {
				$(obj[a]).css("border","1px solid #F11C1C");
			 }else{
				 $(obj[a]).css("border","1px solid #ccc");
			 }*/
			 $(obj[a]).css("border","1px solid #ccc");
		}
	}
	for(var a=0;a<obj.length;a++){
		if($(obj[a]).attr("requir") == "true"){
			 var text = $(obj[a]).val();
			 if(text == "")
			 {
				 return false;
			 }
		}
		var t =  $(obj[a]).val();
		var leng =  $(obj[a]).attr("maxlength");
		try{
			if(t.length>leng && Number(leng)>0){
				 $(obj[a]).css("border","1px solid #F11C1C");
				return false;
			}
			//是否要判断数字
			var s = $(obj[a]).attr("dataValue");
			if(s == "int"){
				if(!f_int(t)){
					$(obj[a]).css("border","1px solid #F11C1C");
					return;
				}
			}else if(s == "tel"){//手机号或电话验证
				if(!f_checkTel(t)){
					$(this).css("border","1px solid #F11C1C");
					return;
				}
			}
		}catch(e){}
		if($(obj[a]).attr("valid") == "true"){
			 var text = $(obj[a]).val();
			 var str = "[@/'\"#$%&^* .,]+";
			 var strForText = text;
			 var reg = new RegExp(str);
			 if(reg.test(strForText))
			 {
				 return false;
			 }
		}
	}
	return true;
}



/**
 * 验证输入框 不显示*号
 */
function f_valid_notshow(attr_name){
	var datetime = $("[class=textbox-value]");

	var obj = $("[valid=true],[requir=true]");
	if(attr_name!=null && attr_name!=""){
		var o = $("["+attr_name+"]");
		obj = [];
		for(var c = 0;c<o.length;c++){
			if($(o[c]).attr("valid") == "true" || $(o[c]).attr("requir") == "true"){
				obj.push(o[c]);
			}
		}
		//obj = $("[valid=true],[requir=true],["+attr_name+"]");
	}
	var cl = $("[cl=tx]");
	for(var c=0;c<cl.length;c++){
		$(cl[c]).remove();
	}
	for(var a=0;a<obj.length;a++){
		if($(obj[a]).attr("requir") == "true"){
			for(var r=0;r<datetime.length;r++){
				if($(datetime[r]).attr("name") == $(obj[a]).attr("textboxname")){
					$(obj[a]).attr("name",$(datetime[r]).attr("name"));
					$(obj[a]).val($(datetime[r]).val());
				}
			}
			 var text = $(obj[a]).val();
			/* if(text == "")
			 {
				 $(obj[a]).css("border","1px solid #F11C1C");
			 }else{
				 $(obj[a]).css("border","1px solid #ccc");
			 }*/
		}
		if($(obj[a]).attr("valid") == "true"){
			 var text = $(obj[a]).val();
			 var str = "[@/'\"#$%&^* .,]+";
			 var strForText = text;
			 var reg = new RegExp(str);
			 /*if(reg.test(strForText))
			 {
				$(obj[a]).css("border","1px solid #F11C1C");
			 }else{
				 $(obj[a]).css("border","1px solid #ccc");
			 }*/
		}
	}
	for(var a=0;a<obj.length;a++){
		if($(obj[a]).attr("requir") == "true"){
			 var text = $(obj[a]).val();
			 if(text == "")
			 {
				 return false;
			 }
		}
		var t =  $(obj[a]).val();
		var leng =  $(obj[a]).attr("maxlength");
		try{
			if(t.length>leng && Number(leng)>0){
				 $(obj[a]).css("border","1px solid #F11C1C");
				return false;
			}
			//是否要判断数字
			var s = $(obj[a]).attr("dataValue");
			if(s == "int"){
				if(!f_int(t)){
					$(obj[a]).css("border","1px solid #F11C1C");
					return;
				}
			}else if(s == "tel"){//手机号或电话验证
				if(!f_checkTel(t)){
					$(this).css("border","1px solid #F11C1C");
					return;
				}
			}
		}catch(e){}

		if($(obj[a]).attr("valid") == "true"){
			 var text = $(obj[a]).val();
			 var str = "[@/'\"#$%&^* .,]+";
			 var strForText = text;
			 var reg = new RegExp(str);
			 if(reg.test(strForText))
			 {
				 return false;
			 }
		}
	}
	return true;
}

/**
 * 输入框验证
 */
function f_v(attr_name){
	var re_msg = "";
	var v_l = $("[requir=true]");
	if(attr_name!=null && attr_name!=""){
		v_l = $("["+attr_name+"][requir=true]");
	}
	for(var a=0;a<v_l.length;a++){
		if($(v_l[a]).val() == ""){
			if($(v_l[a]).attr("lable") == undefined){
				re_msg = re_msg+$(v_l[a]).attr("name")+":不能为空;</br>";
			}else{
				re_msg = re_msg+$(v_l[a]).attr("lable")+":不能为空;</br>";
			}

		}

		if($(v_l[a]).attr("length")!="" && $(v_l[a]).attr("length")!=undefined){
			var l1 = Number($(v_l[a]).attr("length"));
			var l2 = Number($(v_l[a]).val().length);
			if(l2>l1){
				if($(v_l[a]).attr("lable") == undefined){
					re_msg = re_msg+$(v_l[a]).attr("name")+":输入最大长度为"+l1+"个字符;</br>";
				}else{
					re_msg = re_msg+$(v_l[a]).attr("lable")+":输入最大长度为"+l1+"个字符;</br>";
				}
			}
		}
	}


	v_l = $("[valid=true]");
	if(attr_name!=null && attr_name!=""){
		v_l = $("["+attr_name+"][valid=true]");
	}
	for(var a=0;a<v_l.length;a++){
		if($(v_l[a]).attr("dataValue") == "int"){
			if($(v_l[a]).val() != ""){
				if(!f_int($(v_l[a]).val())){
					if($(v_l[a]).attr("lable") == undefined){
						re_msg = re_msg+$(v_l[a]).attr("name")+":只能输入数字;</br>";
					}else{
						re_msg = re_msg+$(v_l[a]).attr("lable")+":只能输入数字;</br>";
					}

				}
			}
		}

		if($(v_l[a]).attr("dataValue") == "tel"){
			if($(v_l[a]).val()!=""){
				if(!f_checkTel($(v_l[a]).val())){
					if($(v_l[a]).attr("lable") == undefined){
						re_msg = re_msg+$(v_l[a]).attr("name")+":只能输入数字;</br>";
					}else{
						re_msg = re_msg+$(v_l[a]).attr("lable")+":只能输入数字;</br>";
					}
				}
			}
		}
	}
	if(re_msg!=""){
		top.layer.alert(re_msg);
		return false;
	}
	return true;
}

/**
 *  页面加载等待页面
 */
function loading(){
	 var height = window.screen.height-250;
	 var width = window.screen.width;
	 var leftW = 300;
	 if(width>1200){
	 	leftW = 500;
	 }else if(width>1000){
	 	leftW = 350;
	 }else {
	 	leftW = 100;
	 }

	 var _html = "<div id='loading' style='position:absolute;left:0;width:100%;height:"+height+"px;top:0;background:#E0ECFF;opacity:0.8;filter:alpha(opacity=80);'><div style='position:absolute;	cursor1:wait;left:"+leftW+"px;top:200px;width:auto;height:16px;padding:12px 5px 10px 30px;background:#fff url(/wlzl/js/themes/default/images/pagination_loading.gif) no-repeat scroll 5px 10px;border:2px solid #ccc;color:#000;'> 正在加载，请等待...</div></div>";
	 $("body").hide();
	 $("body").before(_html);
}


/**
 *  打开对话框
 */
function dialog(url){
	 var height = window.screen.height-250;
	 var width = window.screen.width;
	 var leftW = 300;
	 if(width>1200){
	 	leftW = 500;
	 }else if(width>1000){
	 	leftW = 350;
	 }else {
	 	leftW = 100;
	 }

	 var _html = "<div id='loading' class='pw' style='position:absolute;left:0;width:100%;height:"+height+"px;top:0;background:#E0ECFF;opacity:0.8;filter:alpha(opacity=80);'><div style='cursor1:wait;top:80px;width:"+width+";padding:12px 5px 10px 30px;background:#fff  no-repeat scroll 5px 10px;border:2px solid #ccc;color:#000;'><iframe width=\"100%\" height=\""+height+"\" frameborder=0 framespacing=0 scrolling=yes allowTransparency=\"true\" marginwidth=0  marginheight=0  name=\"dialog\" id=\"dialog\" src=\""+url+"\"></iframe></div></div>";
	 $("body").hide();
	 $("body").before(_html);
}



/**
 *  页面加载等待页面
 */
function loading_table(id){
	 var height = window.screen.height-250;
	 var width = window.screen.width;
	 var leftW = 300;
	 if(width>1200){
	 	leftW = 500;
	 }else if(width>1000){
	 	leftW = 350;
	 }else {
	 	leftW = 100;
	 }
	 var _html = "<div id='loading' style='position:absolute;left:0;width:100%;height:"+height+"px;top:0;background:#E0ECFF;opacity:0.8;filter:alpha(opacity=80);'><div style='position:absolute;	cursor1:wait;left:"+leftW+"px;top:200px;width:auto;height:16px;padding:12px 5px 10px 30px;background:#fff url(/wlzl/js/themes/default/images/pagination_loading.gif) no-repeat scroll 5px 10px;border:2px solid #ccc;color:#000;'>正在加载，请等待...</div></div>";
	 $("#"+id).hide();
	 $("#"+id).before(_html);
}

function close_loading(){
	$("#loading").remove();
	$("body").show();
}

function close_parent_loading(){
	window.parent.$("#loading").remove();
	window.parent.$("body").show();
}

/**
 * 列表数据操作对象
 */
var table_mx = {
	getRowDataAll : [],
	addRowData : function(json){
		table_mx.getRowDataAll.push(json);
	},
	//获取列表的主键
	getTableIdCol : function(){
		var column = grid.columns;
		var idname = "";
		for(var a=0;a<column.length;a++){
			if(column[a].id_col){
				idname = column[a].id_col;
			}
		}
		return idname;
	},
	//获取列表已选择的数据对象
	getRowData : function(){
		var rows = [];
		var id = chks();
		var id_col = table_mx.getTableIdCol();
		var dataAll = table_mx.getRowDataAll;
		for(var a=0;a<dataAll.length;a++){
			for(var i=0;i<id.length;i++){
				if(dataAll[a][id_col] == id[i]){
					rows.push(dataAll[a]);
				}
			}
		}
		return rows;
	}
};


var pageNo = 1;
var gridobj = null;
var gridid = null;
var pageCount = 0;
var pageObject = null;

var gridObj = {};

function gridList(obj,id){
	var ub = obj.url;
	if(ub.indexOf("FrameAction@list.action")!=-1){
		obj.where.where = encodePass(obj.where.where);
	}
	gridObj[id] = {};
	if(obj.pageNo){
		gridObj[id].pageNo = obj.pageNo;
	}
	gridObj[id].gridobj = obj;
	gridObj[id].gridid = id;
	loading_table(id);
	var w = {page:obj.pageNo,rows:obj.pageSize,tableName:obj.table,order:obj.order};
	if(obj.sql){
		obj.sql = encodePass(obj.sql);
		w["sql"] = obj.sql;
	}
	//如果有其它参数，也把参数一起复制到当前参数中
	if(obj.parms){
		copy(obj.parms,w);
	}
	copy(obj.where,w);

	//查询数据
	$.ajax({
		url : obj.url,
		data : w,
		type : "POST",
		headers: {
			secret:getSecret(),
			token:localStorage.getItem("token")
	    },
		success : function(text){
			var j = decode(text);
			gridObj[id].pageObject = j;
			obj.total = j.total;
			var col = obj.columns;
			//输出头部工具条按钮
			var button = getButtonHtml1(obj,Number(getColSum(col)));
			var table = button+'<div class="rightinfo" ><div class="content" id="content_table_id" >';
			var wid = Number($(window).width())+300;
			table = table+'<table class="table_content" >';

			//table = table+button;
			table = table+"<tr>";
			//循环输出表头
			for(var a=0;a<col.length;a++){
				var colspan = "";
				if(col[a].colspan){
					colspan = "colspan=\""+col[a].colspan+"\"";
				}
				if(col[a].checkbox){//如果该列是选择框
					table = table+'<th width="'+col[a].width+'" '+colspan+' ><input type="checkbox"   name="checkAll" title="全选/取消" onclick="f_selectAll(this)" ></th>';
					table = table+'<th width="5%">序号</th>';
				}else{
					if(a == 0){
						table = table+'<th width="5%">序号</th>';
					}
					table = table+'<th width="'+col[a].width+'" '+colspan+'  th="true" >'+col[a].title+'</th>';
				}

			}
			table = table+"</tr>";
			//开始输出数据
			var rows = j.rows;
			for(var i=0;i<rows.length;i++){
				//双数行变颜色
				if(i%2 == 0){
					table = table+"<tr c=''  >";
				}else{
					table = table+"<tr class='listShowBag' c='#F5ECEC'  >";
				}

				var r = rows[i];
				table_mx.addRowData(r);
				var check = false;
				var tm = "";
				for(var a=0;a<col.length;a++){
					var style = getColumnStyle(col[a]);
					var c = col[a].field;
					if(col[a].formatter){
						if(col[a].colspan){
							var vs = col[a].formatter(r[c],r);
							for(var g=0;g<col[a].colspan;g++){
								tm = tm+'<td width="65px" '+style+' onclick="gridTrClick(this)" >'+vs[g]+'</td>';
							}
						}else{
							var c_id = col[a].field+"_"+i+"_"+a;
							col[a]["td_id_ajax"] = c_id;
							var td_id = "td_hidden_"+c_id;
							tm = tm+'<td '+style+' id="'+td_id+'"  colName="'+c+'" onclick="gridTrClick(this)" >'+col[a].formatter(r[c],r,col[a],td_id)+'</td>';
						}
					}else if(col[a].checkbox){//如果该列是选择框
						tm = tm+'<td '+style+' ><input type="checkbox"   name="checkbox_check" value="'+r[col[a].id_col]+'"   colName="'+col[a].id_col+'" /></td>';
						tm = tm+'<td '+style+' onclick="gridTrClick(this)" >'+((pageNo-1)*pageSize+1+i)+'</td>';
						check = true;
					}else{
						var td_value = r[c]==null?"":r[c];
						td_value = td_value=="null"?"":td_value;
						tm = tm+'<td '+style+'  colName="'+c+'" onclick="gridTrClick(this)"  >'+td_value+'</td>';
					}
				}
				if(!check){
					table = table+'<td onclick="gridTrClick(this)" >'+((pageNo-1)*pageSize+1+i)+'</td>';
				}
				table = table+tm;
				table = table+"</tr>";
			}
			table = table+'</table>';
			table = table+"</div>";
			table = table+pager(j,id);
			table = table+"</div>";
			gridObj[id].pageCount = j.pageCount;
			$("#"+id).addClass("body_div");
			$("#"+id).html(table);
			$("#"+id+"_select_pager_select").val(obj.pageSize);
			$("#loading").remove();
			$("#"+id).show();

			$("[name=checkbox_check]").change(function() {
				gridTrColor(this);
			});

			//$("[th=true]").resizable();
			if(obj.alter_fun){
				obj.alter_fun();
			}
		}
	});
}

/**
 * 表头多列形式扩展表格
 */
var gridListColumns = function(obj,id){
	if(pageNo>pageCount){
		pageNo = pageCount;
	}
	if(pageNo<1){
		pageNo = 1;
	}
	if(obj.pageNo){
		pageNo = obj.pageNo;
	}
	gridobj = obj;
	gridid = id;
	loading_table(id);
	var w = {page:pageNo,rows:obj.pageSize,tableName:obj.table};
	copy(obj.where,w);
	//查询数据
	$.ajax({
		url : obj.url,
		data : w,
		type : "POST",
		success : function(text){
			var j = decode(text);
			var col = obj.columns;
			//输出头部工具条按钮
			var button = getButtonHtml1(obj,Number(getColSum(col)));
			var table = button+'<div class="rightinfo" ><div class="content" id="content_table_id" >';
			table = table+'<table class="table_content">';

			//table = table+button;
			table = table+"<tr>";
			var columns_row = "";
			//循环输出表头
			for(var a=0;a<col.length;a++){
				var colspan = "";
				var rowspan = "rowspan=\"2\"";
				if(col[a].colspan){
					colspan = "colspan=\""+col[a].colspan+"\"";
				}
				if(col[a].columns){
					colspan = "colspan=\""+col[a].columns.length+"\"";
					rowspan = "";
					//输出多列表头
					for(var r=0;r<col[a].columns.length;r++){
						columns_row = columns_row+"<th>"+col[a].columns[r].title+"</th>";
					}
				}
				if(col[a].checkbox){//如果该列是选择框
					table = table+'<th width="'+col[a].width+'" '+colspan+' '+rowspan+' ><input type="checkbox"   name="checkAll" title="全选/取消" onclick="f_selectAll(this)" ></th>';
					table = table+'<th width="5%" '+rowspan+' >序号</th>';
				}else{
					if(a == 0){
						table = table+'<th width="5%" '+rowspan+' >序号</th>';
					}
					table = table+'<th width="'+col[a].width+'" '+colspan+' '+rowspan+' >'+col[a].title+'</th>';
				}

			}
			table = table+"</tr>";
			table = table+"<tr>"+columns_row+"</tr>";


			//开始输出数据
			var rows = j.rows;
			for(var i=0;i<rows.length;i++){
				table = table+"<tr>";
				var r = rows[i];
				table_mx.addRowData(r);
				var check = false;
				var tm = "";
				for(var a=0;a<col.length;a++){
					var style = getColumnStyle(col[a]);
					var c = col[a].field;
					if(col[a].formatter){
						if(col[a].colspan){
							var vs = col[a].formatter(r[c],r);
							for(var g=0;g<col[a].colspan;g++){
								tm = tm+'<td width="65px" '+style+' >'+vs[g]+'</td>';
							}
						}else{
							tm = tm+'<td '+style+' >'+col[a].formatter(r[c],r,col[a])+'</td>';
						}
					}else if(col[a].checkbox){//如果该列是选择框
						tm = tm+'<td '+style+' ><input type="checkbox" name="checkbox_check" value="'+r[col[a].id_col]+'"  /></td>';
						tm = tm+'<td '+style+' >'+((pageNo-1)*pageSize+1+i)+'</td>';
						check = true;
					}else if(col[a].columns){//表头多表形式
						for(var ig=0;ig<col[a].columns.length;ig++){
							if(col[a].columns[ig].formatter){
								if(col[a].columns[ig].colspan){
									var vs = col[a].columns[ig].formatter(r[col[a].columns[ig].field],r);
									for(var gr=0;gr<col[a].columns[ig].colspan;gr++){
										tm = tm+'<td width="65px" '+style+' >'+vs[gr]+'</td>';
									}
								}else{
									tm = tm+'<td '+style+' >'+col[a].columns[ig].formatter(r[col[a].columns[ig].field],r)+'</td>';
								}
							}else{
								var td_value = r[col[a].columns[ig].field]==null?"":r[col[a].columns[ig].field];
								tm = tm+'<td '+style+' >'+td_value+'</td>';
							}
						}
					}else{
						var td_value = r[c]==null?"":r[c];
						tm = tm+'<td '+style+' >'+td_value+'</td>';
					}
				}
				if(!check){
					table = table+'<td>'+((pageNo-1)*pageSize+1+i)+'</td>';
				}
				table = table+tm;
				table = table+"</tr>";
			}
			table = table+'</table>';
			table = table+"</div>";
			table = table+pager(j);
			table = table+"</div>";
			pageCount = j.pageCount;
			$("#"+id).addClass("body_div");
			$("#"+id).html(table);
			$("#loading").remove();
			$("#"+id).show();
			$("#"+id).find("th").resizable();
			if(obj.alter_fun){
				obj.alter_fun();
			}
		}
	});
};



function getColumnStyle(colObj){
	var style = "";
	for(var k in colObj){
		if(k!="field" && k!="width" && k!="formatter" && k!="colspan"){
			style = style+' '+k+'="'+colObj[k]+'"';
		}
	}
	return style;
}

function getColSum(col){
	var cols = 0;
	for(var a=0;a<col.length;a++){
		if(col[a].colspan){
			cols = cols+Number(col[a].colspan);
		}else{
			cols++;
		}
	}
	return cols+1;
}

//得到列表头部工具条的按钮
getButtonHtml = function(obj,col){
	//alert(col);
	var html = "";
	if(obj.button){

		var bt = obj.button;
		html = html+"<tr><th colspan=\""+col+"\"><div class=\"toolsli\">";
		html = html+"<ul class=\"toolbar\">";
		for(var a=0;a<bt.length;a++){
			var button_obj = bt[a];
			html = html+"<li onclick='"+button_obj.on+"' ><span><img src='"+button_obj.img+"' /></span>"+button_obj.text+"</li>";
		}
		html = html+"</ul>";
		html = html+"</div></th>";
		html = html+"</tr>";
	}
	return html;
};

var getButtonHtml1 = function(obj,col){
	//alert(col);
	var html = "";
	if(obj.button){

		var bt = obj.button;
		html = html+"<div class=\"toolsli\">";
		html = html+"<ul class=\"toolbar\">";
		for(var a=0;a<bt.length;a++){
			var button_obj = bt[a];
			var html2 = "";
			if(button_obj.html){
				html = html+"<li >"+button_obj.html+"</li>";
			}else{
				if(button_obj.level){
					html2 = "<dl style=\"position: absolute;z-index: 999;color:#000; background-color: #fff;border:1px solid #eaeaea;\">";
					var levs = button_obj.level;
					for(var c=0;c<levs.length;c++){
						html2 = html2+"<dd style=\"border-bottom:1px solid #eaeaea;padding:0px 30px 0px 5px;\" onclick=\""+levs[c].on+"\" >"+levs[c].text+"</dd>";
					}
					html2 = html2+"</dl>";
				}

				var li_h = "";
				for(var k in button_obj){
					if(k!="img" && k!="text" && k!="on"){
						li_h = li_h+""+k+"=\""+button_obj[k]+"\"";
					}
				}
				var img_html = "";
				if(button_obj.img!=undefined && button_obj.img!=""){
					//img_html = "<img src='"+button_obj.img+"' style='width: 15px;height: 15px;margin-top: 4px;' />";
				}
				html = html+"<li onclick='"+button_obj.on+"' "+li_h+" class=\"toolbarli\" style='font-size: 14px;' ><span>"+img_html+"</span>"+button_obj.text+html2+"</li>";
			}

		}
		html = html+"</ul>";
		html = html+"</div>";
		if(bt.length == 0){
			html = "";
		}
	}
	return html;
};

function f_selectAll(obj){
	var table = $(obj).parent().parent().parent();
	var is_check = $(obj).is(":checked");
	var chk = $(table).find("[name=checkbox_check]");
	for(var a=0;a<chk.length;a++){
		if(is_check){
			chk[a].checked = true;
		}else{
			$(chk[a]).removeAttr("checked");
		}
		gridTrColor(chk[a]);
	}
}



function chks(tableId){
	var chk = $("[name=checkbox_check]");
	if(tableId){
		chk = $(tableId).find("[name=checkbox_check]");
	}
	var ids = [];
	for(var a=0;a<chk.length;a++){
		var check = $(chk[a]).is(':checked');
		if(check){
			ids.push($(chk[a]).val());
		}
	}
	return ids;
}

function chkStr(tableId){
	var chk = $("[name=checkbox_check]");
	if(tableId){
		chk = $(tableId).find("[name=checkbox_check]");
	}
	var ids = [];
	for(var a=0;a<chk.length;a++){
		var check = $(chk[a]).is(':checked');
		if(check){
			ids.push("'"+$(chk[a]).val()+"'");
		}
	}
	return ids;
}

getGridWhere = function(o1,o2){

};

var pager = function(page,id){
	var html = '<div class="pages" style="margin-top:0px;" ><div class="dpl-paging" style="margin-top:0px;" >';
	html = html+'<span class="dpl-page-list">';
	html = html+'<a class="dpl-next" onclick=f_per(this)  grid_id="'+id+'" >上一页</a>  <a class="dpl-next" onclick=f_next(this)   grid_id="'+id+'" ><span class="dpl-txt" >下一页</span>';
	html = html+'</a>';

	var se = "<option value='15' >15</option>";
	se = se+"<option value='30' >30</option>";
	se = se+"<option value='50' >50</option>";
	se = se+"<option value='70' >70</option>";
	se = se+"<option value='100' >100</option>";
	se = se+"<option value='200' >200</option>";
	se = se+"<option value='500' >500</option>";
	html = html+'<select  onchange="f_load_grid(this)"  grid_id="'+id+'" id="'+id+'_select_pager_select" >'+se+'</select>';

	html = html+'</span> <span class="dpl-paging-total">当前第'+page.pageNumber+'/'+page.pageCount+'页, 共'+page.total+'条记录</span> <span';
	html = html+' class="dpl-number"><span> 到</span> <input';
	html = html+' class="dpl-text dpl-text-s" type="text" id="pageText" value="'+page.pageNumber+'" maxlength="6"></input><span>页</span></span> <span';

	html = html+' class="dpl-forward"><button class="btn btn-js"';
	html = html+' style="padding:3px 6px;" onclick="f_go(this)"  grid_id="'+id+'"  >确定</button></span>';
	html = html+'</div></div>';

	return html;
};

function f_load_grid(o){
	var id = $(o).attr("grid_id");
	gridObj[id].pageNo = 1;
	gridObj[id].pageSize = $(o).val();
	gridObj[id].gridobj.pageSize = $(o).val();
	gridList(gridObj[id].gridobj, id);
}

function f_per(o){
	var id = $(o).attr("grid_id");

	if(gridObj[id].pageNo == 1){
		alert("当前已经是第一页了");
		return false;
	}
	var pageNo = Number(gridObj[id].pageNo);
	pageNo--;
	gridObj[id].gridobj.pageNo = pageNo;
	gridList(gridObj[id].gridobj, id);
}
function f_next(o){
	var id = $(o).attr("grid_id");
	if(gridObj[id].pageNo == gridObj[id].pageObject.pageCount){
		alert("当前已经是最后一页了");
		return false;
	}
	var pageNo = Number(gridObj[id].pageNo);
	pageNo++;
	gridObj[id].gridobj.pageNo = pageNo;
	gridList(gridObj[id].gridobj, id);
}

function f_go(o){
	var id = $(o).attr("grid_id");
	gridObj[id].gridobj.pageNo = $("#"+id).find("#pageText").val();

	if(Number(gridObj[id].pageNo)<1){
		alert("输入页码不能小于等于0");
		return false;
	}
	if(Number(gridObj[id].pageNo) > gridObj[id].pageObject.pageCount){
		alert("当前已经是最后一页了");
		return false;
	}

	gridList(gridObj[id].gridobj, id);
}

/**
 * 当前页面刷新跳转
 * @param url 要跳转的URL
 */
function f_location(url){
	var h = window.screen.height-250;
	$("#listDiv").hide();
	$("#loadnextPage_div").html('<iframe width="100%" frameborder=0 framespacing=0 scrolling=yes marginheight=0 width="100%" height="'+h+'" src="'+url+'"  scrolling="auto"  />');
}

function f_back(){
	window.parent.$("#listDiv").show();
	window.parent.$("#loadnextPage_div").html("");
}


var submit_pass = "382b2f94-dcba-45ec-9274-967cd5e19d5d";


/**
 * 对字符串进行加密码，
 * @param str 要加密码的字符串
 * @param passStr 密码，如果不传此参数，就用系统的
 */
function encodePass(str,passStr){
	var pass = "";
	if(passStr!="" && passStr!=null){
		pass = passStr;
	}else{
		pass = submit_pass;
	}
	var b = new Base64();
	var v = str;
	v = b.encode(v);
	var vs = v.split("");
	var j_v = "";
	for(var a=0;a<vs.length;a++){
		j_v = j_v+vs[a]+pass;
	}
	v = b.encode(j_v);
	return v;
}


/**
 * 根据字符串和密码进行解密，把数据还原
 * @param str
 * @param passStr
 */
function decodePass(str,passStr){
	var pass = "";
	if(passStr!="" && passStr!=null){
		pass = passStr;
	}else{
		pass = submit_pass;
	}
	var v = str;
	var b = new Base64();
	v = b.decode(v);
	var vs = v.split(pass);
	var j_v = "";
	for(var a=0;a<vs.length;a++){
		j_v = j_v+vs[a];
	}
	v = b.decode(j_v);
	return v;
}



/**
 * 日期比较
 * @param date1 基准日期（现在的日期）
 * @param date2 要比较的日期
 * @returns {Number}
 */
function dateCompare(date1,date2){
	date1 = date1.replace(/\-/gi,"/");
	date2 = date2.replace(/\-/gi,"/");
	var time1 = new Date(date1).getTime();
	var time2 = new Date(date2).getTime();
	if(time1 > time2){
		return 1;
	}else if(time1 == time2){
		return 2;
	}else{
		return 3;
	}
}


window.setTimeout("f_pageInit()",350);
function f_pageInit(){
	top.$("#loadingLeft").hide();
	top.$("#leftFrame").show();
	top.$("#loadingRight").hide();
	top.$("#rightFrame").show();
}


/**
 * 当前日期加时间(如:2009-06-12 12:00)
 * @returns {String}
 */
function getCurentTime() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = now.getDate(); //日

	var hh = now.getHours(); //时
	var mm = now.getMinutes(); //分
	alert(mm);
	var clock = year + "-";

	if (month < 10)
		clock += "0";

	clock += month + "-";

	if (day < 10)
		clock += "0";

	clock += day + " ";

	if (hh < 10)
		clock += "0";

	clock += hh + ":";
	if (mm < 10){
		clock += '0';
	}

	clock += mm;

	return clock;
}


function f_input_select_class(){
	var selects = $("select");
	for(var a=0;a<selects.length;a++){
		$(selects[a]).addClass("input_select fr");
	}
	var input = $("input");
	for(var a=0;a<input.length;a++){
		if($(input[a]).attr("type")!="checkbox"){
			$(input[a]).addClass("input_add fr");
		}

	}
}

/**
 * 产品随机数
 * @param Min
 * @param Max
 * @returns
 */
function GetRandomNum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}

/**
 * 获取对象的长度
 * @param obj
 * @returns {Number}
 */
function ObjectSize(obj) {
    var size = 0, key;
    for (key in obj) {
        size++;
    }
    return size;
};

/**
 * 电话和手机号验证
 */
function f_checkTel(tel)
{
   var mobile = /^1[3|5|8]\d{9}$/ , phone = /^0\d{2,3}-?\d{7,8}$/;
   return mobile.test(tel) || phone.test(tel);
}



/*
 * 根据当前的时间，渲染年月日时分秒
 */
function renderTime(date,type){
	var hours = new Date(date).getHours(),
		minutes = new Date(date).getMinutes(),
		seconds = new Date(date).getSeconds(),
		year = new Date(date).getFullYear(),
		month = new Date(date).getMonth(),
		date_ = new Date(date).getDate(),
		curTime;
	if(year<10){
		year = "0"+year;
	}
	month = month+1;
	if(month<10){
		month = "0"+month;
	}
	if(date_<10){
		date_ = "0"+date_;
	}
	if(hours < 10) {
		hours = '0' + hours;
	}
	if(minutes < 10) {
		minutes = '0' + minutes;
	}
	if(seconds < 10) {
		seconds = '0' + seconds;
	}
	if(type == 'yyyy-MM-dd HH:mm:ss') {
		curTime = year+"-"+month+"-"+date_+" "+ hours + ":" + minutes + ":" + seconds;
	}else if(type == 'yyyy-MM-dd HH:mm') {
		curTime = year+"-"+month+"-"+date_+" "+ hours + ":" + minutes;
	}else if(type == 'yyyy-MM-dd') {
		curTime = year+"-"+month+"-"+date_;
	}
	return curTime;
}


/**
 * layer加载
 */
function load(){
	var index = layer.msg("加载中", {icon: 16,shade: [0.5, '#f5f5f5'], time:-1});
	return index;
}


/**
 * element加载
 * @returns {*|undefined}
 */
function loading(obj){
	if(obj == undefined){
		obj = vm;
	}
	const loading = obj.$loading({
		lock: true,
		text: '加载中...',
		spinner: 'el-icon-loading',
		background: 'rgba(0, 0, 0, 0.7)'
	});
	return loading;
}



/**
 * 获取列表当前选择的整行数据
 */
function getTableRowData(tableid){
	var ids = chks();
	if(ids.length == 0){
		alert("请选择记录");
		return;
	}

	var rows = $("#"+tableid).find(".table_content").find("tr");
	var rowdata_list = [];
	var r = 0;
	for(var a=1;a<rows.length;a++){
		var cols = $(rows[a]).find("td");
		var mapdata = {};
		var id_col = "";
		for(var b=0;b<cols.length;b++){
			if($(cols[b]).attr("id_col")!="" && $(cols[b]).attr("id_col")!=null && $(cols[b]).find("input").length>0){
				id_col = $(cols[b]).attr("id_col");
				var checkbox = $(cols[b]).find("input");
				mapdata[$(cols[b]).attr("id_col")] = $(checkbox[0]).val();
			}else{
				mapdata[$(cols[b]).attr("colName")] = $(cols[b]).html();
			}

		}
		for(var bb=0;bb<ids.length;bb++){
			if(ids[bb] == mapdata[id_col]){
				rowdata_list[r] = mapdata;
				r++;
			}
		}
	}
	return rowdata_list;
}

/**
 * 列表grid行点击后变颜色
 * @param o 被点击行对象
 * @param tableid 表ID
 */
function gridTrColor(o){
	var check = $(o).is(':checked');
	var tr = $(o).parent().parent();
	if(check){
		$(tr).addClass("listTableRow");
	}else{
		$(tr).removeClass("listTableRow");
	}


}

function gridTrClick(o){
	var tr = $(o).parent();
	var check = $(tr).find("[name=checkbox_check]");
	var is_check = $(check).is(":checked");
	if(is_check){
		$(check).removeAttr("checked");
	}else{
		check[0].checked = true;
	}
	gridTrColor(check[0]);
}



/**
*
*  Base64 encode / decode
*
*  @author haitao.tu
*  @date   2010-04-26
*  @email  tuhaitao@foxmail.com
*
*/

function Base64() {

    // private property
    _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    // public method for encoding 编码方法
    this.encode = function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        input = _utf8_encode(input);
        while (i < input.length) {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
            _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
            _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
        }
        return output;
    };

    // public method for decoding 解码方法
    this.decode = function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        while (i < input.length) {
            enc1 = _keyStr.indexOf(input.charAt(i++));
            enc2 = _keyStr.indexOf(input.charAt(i++));
            enc3 = _keyStr.indexOf(input.charAt(i++));
            enc4 = _keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
        }
        output = _utf8_decode(output);
        return output;
    };

    // private method for UTF-8 encoding
    _utf8_encode = function (string) {
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            } else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }
        return utftext;
    };

    // private method for UTF-8 decoding
    _utf8_decode = function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while ( i < utftext.length ) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            } else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            } else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    };
}

/**
 * 根据指定的文件选择对象，选择文件后开始上传文件。
 * @returns {Boolean}
 */
function f_all_upload(fileObj,org_id,success){
	var l = $(fileObj)[0].files;
	for(var a=0;a<l.length;a++){
		var file = l[a];  //文件对象
        var name = file.name;
        var size = file.size;
        if(size>0){
        	size = size/1024/1024;
        	size = size.toFixed(2);
        	f_upload(file,org_id,success);
        }
	}

}

var load_id = "";

//上传文件
function f_upload(file,org_id,success){
    var name = file.name;

    var size = file.size;

    var shardSize = 1024*1024*2;
    var shardCount = Math.ceil(size / shardSize);
    var fileExtension = name.substring(name.lastIndexOf(".") + 1);
    var t = org_id+"/"+new Date().getTime()+"/"+new Date().getTime()+"."+fileExtension;
    var succeed = 0;

    var i = 0;
    load_id = load();
    f_up(file,i,shardSize,succeed,t,shardCount,success);

}


function f_up(file,i,shardSize,succeed,t,shardCount,success){
	var size = file.size;        //总大小
	//计算每一片的起始与结束位置
    var start = i * shardSize;
    var end = Math.min(size, start + shardSize);

  //构造一个表单，FormData是HTML5新增的
    var form = new FormData();
    form.append("data", file.slice(start,end));  //slice方法用于切出文件的一部分
    $.ajax({
        url: rootPath+"/ShellFileUpload.shellFileUpload?fileName="+t+"&seek="+start,
        type: "POST",
        data: form,
        async: true,        //异步
        processData: false,  //很重要，告诉jquery不要对form进行处理
        contentType: false,  //很重要，指定为false才能形成正确的Content-Type
        success: function(){
        	++succeed;
        	var pro = succeed/shardCount*100;
        	pro = pro.toFixed(2);
            if(succeed == shardCount && success){
            	layer.close(load_id);
            	success({"path":"/upload/"+t,"fileLength":size,"fileName":file.name});
            }else{
            	i++;
            	f_up(file,i,shardSize,succeed,t,shardCount,success);
            }
        }

    });
}

/**
 * 获取主页面弹出框，调用弹出框中的iframe中的方法
 * @param layero
 * @returns
 */
function getTopIframe(layero){
	 var iframeWin = top.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	 return iframeWin;
}






function f_max_open(url,title,buttons,closeFun,layer_id){
	var config = {
	  id :layer_id,
	  title:title,
	  type: 2,
	  content: url,
	  area: ['320px', '195px'],
	  maxmin: true,
	  end: function () {
		  if(closeFun){
			  closeFun();
		  }
      },cancel: function(){
    	  var index = layer.getFrameIndex(layer_id); //先得到当前iframe层的索引
		  layer.close(index);
    	  return true;
      }
	};
	if(buttons){
		copy(buttons,config);
	}
	//弹出即全屏
	var index = layer.open(config);
	layer.full(index);
}


/**
 * grid列表选中后变颜色
 * is_this:是否只能选择一行，如果只能选择一行，则会把其它选择的行颜色变为正常
 */
function f_click_row_bcg(trObj,is_this){
	var o = trObj;
	var tr = $(o).parent();
	var id = $(tr).find("[name=checkbox_check]").val();
	var check = $(tr).find("[name=checkbox_check]");
	var is_cg = $(tr).is(".listTableRow");
	if(is_this){
		var trs = $(tr).parent().find("tr");
		for(var a=0;a<trs.length;a++){
			$(trs[a]).removeClass("listTableRow");
			var ch = $(trs[a]).find("[name=checkbox_check]");
			$(ch).removeAttr("checked");
		}
	}
	if(is_cg){
		$(tr).removeClass("listTableRow");
		check[0].checked = false;
	}else{
		$(tr).addClass("listTableRow");
		check[0].checked = true;
	}

}
/**
 * ajax请求封装
 * @param url
 * @param data
 * @param succ
 */
function post(url,data,succ){
	if(succ == undefined){
		return new Promise((resolve,reject)=>{
			$.ajax({
				url:wwwurl+url,
				type:"POST",
				headers: {
					secret:getSecret(),
					token:localStorage.getItem("token")
				},
				data:data,
				success:function(msg){
					resolve(msg);
				}
			});
		})
	}else {
		$.ajax({
			url:wwwurl+url,
			type:"POST",
			headers: {
				secret:getSecret(),
				token:localStorage.getItem("token")
			},
			data:data,
			success:function(msg){
				succ(msg);
			}
		});
	}

}

/**
 * 自定义接口请求
 * @param ids
 * @param mapdata
 * @param tableId
 * @param treeNode
 * @param succ
 */
function postCustom(ids,mapdata,tableId,treeNode,succ) {
	let url = "/admin/api/DataManagementController/customPostData";
	let param = {
		"ids": ids,
		"mapdata": mapdata,
		"tableId": tableId,
		"treeNode": treeNode
	}
	postBody(url,param,succ);
}

/**
 * ajax请求封装
 * @param url
 * @param data
 * @param succ
 */
function httpGet(url,data,succ){
	if(succ == undefined){
		return new Promise((resolve,reject)=>{
			$.ajax({
				url:wwwurl+url,
				type:"GET",
				headers: {
					secret:getSecret(),
					token:localStorage.getItem("token")
				},
				data:data,
				success: function (jsonResult) {
					resolve(jsonResult);
				}
			});
		})
	}else {
		$.ajax({
			url:wwwurl+url,
			type:"GET",
			headers: {
				secret:getSecret(),
				token:localStorage.getItem("token")
			},
			data:data,
			success:function(msg){
				succ(msg);
			}
		});
	}

}

function postBodyNotHeaders(url,data){
	return new Promise((resolve,reject)=>{
		if(url.indexOf("http") == -1){
			url = wwwurl+url;
		}
		$.ajax({
			type: "POST",
			url: url,
			contentType: "application/x-www-form-urlencoded",
			dataType: "json",
			data: JSON.stringify(data),
			success: function (jsonResult) {
				resolve(jsonResult);
			}
		});
	})
}

function postBody(url,data,succ){
	if(succ == undefined){
		return new Promise((resolve,reject)=>{
			$.ajax({
				type: "POST",
				url: wwwurl+url,
				headers: {
					secret:getSecret(),
					token:localStorage.getItem("token")
				},
				contentType: "application/json",
				dataType: "json",
				data: JSON.stringify(data),
				success: function (jsonResult) {
					resolve(jsonResult);
				}
			});
		})
	}else {
		console.log("data",data);
		$.ajax({
			type: "POST",
			url: wwwurl+url,
			headers: {
				secret:getSecret(),
				token:localStorage.getItem("token")
			},
			contentType: "application/json",
			dataType: "json",
			data: JSON.stringify(data),
			success: function (jsonResult) {
				succ(jsonResult);
			}
		});
	}

}







/**
 * form表单提交，通知POST方式进行提交
 */
function postForm(url,parms){
	var turnForm = document.createElement("form");
    // 一定要加入到body中！！
    document.body.appendChild(turnForm);
    turnForm.method = 'post';
    turnForm.action = url;
    //turnForm.target = '_blank';

    for(var k in parms){
    	// 创建隐藏表单
        var newElement = document.createElement("input");
        newElement.setAttribute("name",k);
        newElement.setAttribute("type","hidden");
        newElement.setAttribute("value",parms[k]);
        turnForm.appendChild(newElement);
    }
    turnForm.submit();
}


/**
 * 过滤特殊字符串
 * @param str
 * @returns
 */
function replaceAll(str){
	str = str.replace(/[^\u4e00-\u9fa5\w]/g,'');
	return str;
}




function getParams(){
	var params = location.search;
	params = params.substr(1);//去掉问号
	let ps = params.split("&");
	let mapdata = {};
	for(let a=0;a<ps.length;a++){
		if(ps[a] != ""){
			let kandv = ps[a].split("=");
			mapdata[kandv[0]] = kandv[1];
		}
	}
	return mapdata;
}

function alert(msg){
	top.alertSuccess(msg);
}



function getSecret(){
	var secret = localStorage.getItem("secret");
	// 获取时间戳
	let date = new Date();
	let strdate = renderTime(date,"yyyy-MM-dd HH:mm");
	strdate = strdate.replace("-","/");
	let newDate = new Date(strdate).getTime();
	//let hash = hex_md5(newDate+""+secret);
	let hash = newDate;
	return hash;
}



//生成UUID的方法
function guid() {
	function S4() {
		return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	}
	return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}


/**
 * 获取真实表id
 * @param tableId
 * @returns {string|*}
 */
function getTableId(tableId){
	if(tableId.indexOf("-")!=-1){
		return tableId;
	}
	let userstr = localStorage.getItem("user");
	if(userstr!=undefined && userstr!=""){
		let user = JSON.parse(userstr);
		let keycode = user.org_id;
		if(keycode!=undefined && keycode!=""){
			return keycode+"-"+tableId;
		}
	}
	return tableId;
}

/**
 * 自定义接口请求
 * @param tableId 表id
 * @param mapdata 参数数据
 * @returns {Promise<AxiosResponse<any>>}
 */
function postWebCustom(tableId,mapdata) {
	let param = {
		"mapdata": mapdata,
		"tableId": tableId
	}
	const res = postBody("/admin/api/CommonDataProcessingController/postCustom",param);
	return res;
}


/**
 * 共公分页查询
 * @param tableId 表id
 * @param orderBy 排序号
 * @param pageNumber 第几页
 * @param pageSize 每页多少条记录
 * @param where 查询条件 例子:{'a':'1','b':'2'}
 * @returns {Promise<AxiosResponse<any>>}
 */
function page(tableId, orderBy, pageNumber, pageSize, where) {
	tableId = getTableId(tableId);
	let param = {
		"orderBy": orderBy,
		"pageNumber": pageNumber,
		"pageSize": pageSize,
		"tableId": tableId,
		"where": getPostWhere(where)
	}
	const res = postBody("/admin/api/CommonDataProcessingController/list", param);
	return res;
}

/**
 * 共公分页查询
 * @param tableId 表id
 * @param orderBy 排序号
 * @param pageNumber 第几页
 * @param pageSize 每页多少条记录
 * @param where 查询条件 例子:[{},{}]
 * @returns {Promise<AxiosResponse<any>>}
 */
function pageWhereList(tableId, orderBy, pageNumber, pageSize, where) {
	tableId = getTableId(tableId);
	let param = {
		"orderBy": orderBy,
		"pageNumber": pageNumber,
		"pageSize": pageSize,
		"tableId": tableId,
		"where": where
	}
	const res = postBody("/admin/api/CommonDataProcessingController/list", param);
	return res;
}


/**
 * 数据列表不分页查询 可返回全部
 * @param tableId 表id
 * @param orderBy 排序号
 * @param where 查询条件 例子:{'a':'1','b':'2'}
 * @returns {Promise<AxiosResponse<any>>}
 */
function list(tableId, orderBy, where) {
	tableId = getTableId(tableId);
	let param = {
		"orderBy": orderBy,
		"tableId": tableId,
		"where": getPostWhere(where)
	}
	const res = postBody("/admin/api/CommonDataProcessingController/listWhereAll", param);
	return res;
}



/**
 * 数据列表不分页查询 可返回全部，可调用后台自定义查询接口
 * @param tableId 表id
 * @param orderBy 排序号
 * @param where 查询条件 例子:{'a':'1','b':'2'}
 * @returns {Promise<AxiosResponse<any>>}
 */
function listAdmin(tableId, orderBy, where) {
	tableId = getTableId(tableId);
	let param = {
		"orderBy": orderBy,
		"tableId": tableId,
		"isCustomPage":"1",
		"where": getPostWhere(where)
	}
	const res = postBody("/admin/api/CommonDataProcessingController/listWhereAll", param);
	return res;
}


function getPostWhere(where) {
	let whereList = [];
	let type = typeof('[1,2]');
	let str = JSON.stringify(where);
	if (str.substring(0, 1) == '[') {
		for (let a = 0; a < where.length; a++) {
			let mapkey = where[a];
			for (let key in mapkey) {
				if (key != "type" && key != "start" && key != "end") {
					whereList.push(getWhere(mapkey, key))
				}
			}
		}
		return whereList;
	}
	for (let key in where) {
		if (key != "type" && key != "start" && key != "end") {
			whereList.push(getWhere(where, key));
		}

	}
	return whereList;
}

function getWhere(where, key) {
	let mapdata = {
		key: key,
		type: "6",
	};
	if(Array.isArray(where[key])){
		mapdata["values"] = where[key];
	}else {
		mapdata["value"] = where[key];
	}
	if (where['type'] == undefined || where['type'] == "") {
		mapdata["type"] = "6";
	} else if (where["type"] == "5") {
		let datedto = {};
		if (where["start"] != undefined) {
			datedto["start"] = where["start"];
		}
		if (where["end"] != undefined) {
			datedto["end"] = where["end"];
		}
		mapdata["type"] = "5";
		mapdata["searchTypeForDateDto"] = datedto;
	} else {
		mapdata["type"] = where['type'];
	}

	return mapdata;
}

/**
 * 查询一条数据
 * @param tableId 表Id
 * @param id 数据Id
 * @param input_id 录入界面id
 * @returns {Promise<unknown> | undefined}
 */
function queryDataForId(tableId,id,other){
	tableId = getTableId(tableId);
	const resq = postBody("/admin/api/DataManagementController/queryDataForId",{tableId: tableId,ids:""+id,other:other});
	return resq;
}


/**
 * 后台分页查询
 * @param PageSimple
 * @returns {Promise<unknown> | undefined}
 */
function pageAdmin(PageSimple){
	const res = postBody("/admin/api/DataManagementController/list",PageSimple);
	return res;
}


/**
 * 后台数据更新
 * @param tableId
 * @param mapdata
 * @returns {Promise<unknown> | undefined}
 */
function updateMapdata(tableId,mapdata){
	tableId = getTableId(tableId);
	let pdata = {tableId: tableId,
		mapdata: mapdata,
		other: {"type":"saveUpdate"}};
	const resq = postBody("/admin/api/DataManagementController/update",pdata);
	return resq;
}


/**
 * 调用前端接口更新
 * @param tableId
 * @param mapdata
 * @returns {Promise<unknown> | undefined}
 */
function updateData(tableId,mapdata){
	tableId = getTableId(tableId);
	let pdata = {tableId: tableId,
		mapdata: mapdata};
	const resq = postBody("/admin/api/CommonDataProcessingController/update",pdata);
	return resq;
}


/**
 * 新增数据
 * @param tableId
 * @param mapdata
 * @param other
 * @returns {Promise<unknown> | undefined}
 */
function addMapdata(tableId,mapdata){
	tableId = getTableId(tableId);
	let pdata = {tableId: tableId,
		mapdata: mapdata,
		other: {"type":"add"}};
	const resq = postBody("/admin/api/DataManagementController/add",pdata);
	return resq;
}


/**
 * 新增数据(调用前端接口)
 * @param tableId 表Id
 * @param mapdata 要提交的数据
 * @returns {Promise<AxiosResponse<any>>}
 */
function addData(tableId, mapdata) {
	tableId = getTableId(tableId);
	let param = {
		"mapdata": mapdata,
		"tableId": tableId
	}
	const res = postBody("/admin/api/CommonDataProcessingController/add", param);
	return res;
}

/**
 * 删除数据
 * @param tableId
 * @param ids
 * @param other
 * @returns {Promise<unknown> | undefined}
 */
function deleteData(tableId,ids,other){
	tableId = getTableId(tableId);
	let pdata = {tableId: tableId,
		ids: ids,
		other: other};
	const resq = postBody("/admin/api/DataManagementController/delete",pdata);
	return resq;
}

/**
 * 判断两个对象内容是否相同
 * @param obj1 对象1
 * @param obj2 对象2
 * @returns {boolean}
 */
function diff(obj1, obj2) {
	let o1 = obj1 instanceof Object;
	let o2 = obj2 instanceof Object;

	//Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,
	//例如：数组返回下表：let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2;
	if (Object.keys(obj1).length !== Object.keys(obj2).length) {
		return false;
	}

	for (let o in obj1) { // 遍历对象 fon in 循环 o 为 对象的属性名
		let str = JSON.stringify(obj1[o]);
		if (str.substring(0, 1) != '[') {
			for(let a in obj1[o]){
				if(obj1[o][a] != obj2[o][a]){
					return false;
				}
			}
		}
	}
	return true;
}


/**
 * 防抖动函数
 * @param fn要执行的方法
 * @param delay 间隔时间阀值
 * @returns {function(): void}
 */
// fn是我们需要包装的事件回调, delay是时间间隔的阈值
function throttle(fn, delay) {
	// last为上一次触发回调的时间, timer是定时器
	let last = 0, timer = null
	// 将throttle处理结果当作函数返回

	return function () {
		// 保留调用时的this上下文
		let context = this
		// 保留调用时传入的参数
		let args = arguments
		// 记录本次触发回调的时间
		let now = +new Date()

		// 判断上次触发的时间和本次触发的时间差是否小于时间间隔的阈值
		if (now - last < delay) {
			// 如果时间间隔小于我们设定的时间间隔阈值，则为本次触发操作设立一个新的定时器
			clearTimeout(timer)
			timer = setTimeout(function () {
				last = now
				fn.apply(context, args)
			}, delay)
		} else {
			// 如果时间间隔超出了我们设定的时间间隔阈值，那就不等了，无论如何要反馈给用户一次响应
			last = now
			fn.apply(context, args)
		}
	}
}







